package com.example;

import javax.sql.DataSource;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

/**
 * @author yeqiang
 * @since 4/13/21 2:04 PM
 */
public class NamingClient {
    public static void main(String[] args) throws RemoteException, NotBoundException, MalformedURLException {
        FastJsonInjectorImpl fastJsonInjector;


        try {
            String remoteAddr = "rmi://127.0.0.1:7777/rmiService";
            RMIService rmiService = (RMIService) Naming.lookup(remoteAddr);
            String response = rmiService.helloRMI();
            System.out.println("=======> " + response + " <=======");


            DataSource fastJsonInjector2 = (DataSource) Naming.lookup("rmi://127.0.0.1:7777/fastJsonInjector");
            System.out.println(fastJsonInjector2.toString());
            RMIService ds = (RMIService) Naming.lookup("rmi://127.0.0.1:7777/fastJsonInjector");
            System.out.println(ds);

        } catch (NotBoundException | RemoteException | MalformedURLException e) {
            e.printStackTrace();
        }
    }
}
